<%--

  @author yulezhisi
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>销售机会管理主页面</title>

    <link rel="shortcut icon" href="<c:url value="/images/favicon.ico"/>" type="image/x-icon"/>
    <script src="<c:url value="/js/jquery-1.9.1.min.js"/>"></script>
    <script src="<c:url value="/layui/layui.js"/>"></script>
    <link rel="stylesheet" type="text/css" href="<c:url value="/layui/css/layui.css"/>">

    <script src="<c:url value="/js/my/commons.js"/>"></script>
    <style>
        .container {
            width: 1200px;
            margin: 100px auto;
        }
        table{
            width: 100%;
        }
    </style>
</head>
<body>

<div>
    <div class="layui-fluid">
        <div class="layui-card">

            <div class="layui-form layuiadmin-card-header-auto" lay-filter="layadmin-userfront-formlist"
                 style="margin-left: 300px;margin-bottom: 50px;margin-top: 100px">
                <div class="layui-form-item">

                    <div class="layui-btn-group demoTable">
                        <button id="add" lay-event="add" class="layui-btn">新建客户</button>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">客户名称</label>
                        <div class="layui-input-block">
                            <input id="name" name="name"
                                   type="text" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">概要</label>
                        <div class="layui-input-block">
                            <input id="general" name="general"
                                   type="text" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">联系人</label>
                        <div class="layui-input-block">
                            <input id="customerName" name="customerName"
                                   type="text" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <button id="search" class="layui-btn layuiadmin-btn-useradmin lay-submit"
                                lay-filter="LAY-user-front-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>

                </div>
            </div>

            <table id="test" lay-filter="test" class="layui-hide" height=100></table>

            <div>

                <script type="text/html" id="table-useradmin-webuser">

                    <a id="zp" lay-event="zp" class="layui-btn layui-btn-normal layui-btn-xs">
                        <i class="layui-icon layui-icon-edit"></i>指派
                    </a>

                    <a id="bj" lay-event="bj" class="layui-btn layui-btn-danger layui-btn-xs">
                        <i class="layui-icon layui-icon-file-b"></i>編輯
                    </a>

                    <a id="sc" lay-event="sc" class="layui-btn layui-btn-xs">
                        <i class="layui-icon layui-icon-delete"></i>刪除
                    </a>

                </script>

            </div>

    </div>
    </div>
</div>

<script>

    layui.use(['form','table','layer','laydate','layedit'], function(){
        var $ = layui.$
            ,table = layui.table
            ,form = layui.form
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,layedit = layui.layedit;

        //表格
        table.render({
            elem: '#test'
            ,url: '<c:url value="/OpportunitySelectAll.do"/>' //模拟接口
            ,cols: [[
                {field: 'sale_opportunityId', title: 'sale_opportunityId',style:'display:none;'}
                ,{field: 'customerId', title: 'customerId',style:'display:none;'}
                ,{field: 'linkmanId', title: 'id' ,style:'display:none;'}
                //创建人
                ,{field: 'creater', title: 'creater',style:'display:none;'}
                //机会描述
                ,{field: 'description', title: 'description',style:'display:none;'}
                //几率
                ,{field: 'success', title: 'success',style:'display:none;'}
                //来源
                ,{field: 'source', title: 'source',style:'display:none;'}
                //ROWNU
                // ,{field: 'rownu', title: 'id' ,width:51}
                ,{field: 'name', title: '客户名称',width:120}
                ,{field: 'general', title: '概要' ,templet: '#imgTpl',width:215}
                ,{field: 'customerName', title: '联系人',width:153}
                ,{field: 'mobile_phone', title: '联系电话',width:220}
                ,{field: 'create_date', title: '创建时间',width:264}
                ,{title: '操作', align:'center', fixed: 'right', toolbar: '#table-useradmin-webuser',minWidth:280}
            ]]
            ,page: true
            // 表格ID，必须设置，重载部分需要用到
            , id: 'tableOne'
            ,limits: [5,10, 15, 20, 25]
            ,limit: 10
            ,text: '对不起，加载出现异常！'
            /**
             * response:{
                statusName: '自定义的参数名称' ,// 对应 code
                msgName: '自定义的参数名称' , // 对应 msg
                countName: '自定义的参数名称' , // 对应 count
                dataName: '自定义的参数名称' // 对应 data
                }
             */
            ,response: {
                statusName: 'code',// 对应 code
                msgName: 'mag', // 对应 msg
                countName: 'count', // 对应 count
                dataName: 'data'  // 对应 data
            }
            ,text:{none: '无数据'}
        });

        $('table.layui-table thead tr th:eq(0)').addClass('layui-hide');
        $('table.layui-table thead tr th:eq(1)').addClass('layui-hide');
        $('table.layui-table thead tr th:eq(2)').addClass('layui-hide');
        $('table.layui-table thead tr th:eq(3)').addClass('layui-hide');
        $('table.layui-table thead tr th:eq(4)').addClass('layui-hide');
        $('table.layui-table thead tr th:eq(5)').addClass('layui-hide');
        $('table.layui-table thead tr th:eq(6)').addClass('layui-hide');
        //------------------------------------------------------------------------------------------------------------

        // 执行搜索，表格重载
        $('#search').click(function () {
            // 搜索条件
            var general = $('#general').val();
            var customerName = $('#customerName').val();
            var name = $('#name').val();
            table.reload('tableOne',{
                elem: '#test'
                ,method:'post'
                ,where: {
                    'name': name,
                    'general': general,
                    'customerName': customerName,
                }
                ,url: '<c:url value="/QueryOpportunitySelectAll.do"/>' //模拟接口
                ,page: true
                ,limits: [5,10, 15, 20, 25]
                ,limit: 10
                ,text: '对不起，加载出现异常！'
                /**
                 * response:{
                    statusName: '自定义的参数名称' ,// 对应 code
                    msgName: '自定义的参数名称' , // 对应 msg
                    countName: '自定义的参数名称' , // 对应 count
                    dataName: '自定义的参数名称' // 对应 data
                    }
                 */
                ,response: {
                    statusName: 'code',// 对应 code
                    msgName: 'mag', // 对应 msg
                    countName: 'count', // 对应 count
                    dataName: 'data'  // 对应 data
                }
                ,cols: [[
                    {field: 'sale_opportunityId', title: 'sale_opportunityId',style:'display:none;'}
                    ,{field: 'customerId', title: 'customerId',style:'display:none;'}
                    ,{field: 'linkmanId', title: 'id' ,style:'display:none;'}
                    //创建人
                    ,{field: 'creater', title: 'creater',style:'display:none;'}
                    //机会描述
                    ,{field: 'description', title: 'description',style:'display:none;'}
                    //几率
                    ,{field: 'success', title: 'success',style:'display:none;'}
                    //来源
                    ,{field: 'source', title: 'source',style:'display:none;'}
                    //ROWNU
                    // ,{field: 'rownu', title: 'id' ,width:51}
                    ,{field: 'name', title: '客户名称',width:120}
                    ,{field: 'general', title: '概要' ,templet: '#imgTpl',width:415}
                    ,{field: 'customerName', title: '联系人',width:153}
                    ,{field: 'mobile_phone', title: '联系电话',width:220}
                    ,{field: 'create_date', title: '创建时间',width:264}
                    ,{title: '操作', align:'center', fixed: 'right', toolbar: '#table-useradmin-webuser',width:480}

                ]]
                ,text:{none: '无数据'}
            });
            $('table.layui-table thead tr th:eq(0)').addClass('layui-hide');
            $('table.layui-table thead tr th:eq(1)').addClass('layui-hide');
            $('table.layui-table thead tr th:eq(2)').addClass('layui-hide');
            $('table.layui-table thead tr th:eq(3)').addClass('layui-hide');
            $('table.layui-table thead tr th:eq(4)').addClass('layui-hide');
            $('table.layui-table thead tr th:eq(5)').addClass('layui-hide');
            $('table.layui-table thead tr th:eq(6)').addClass('layui-hide');
        });


        //------------------------------------------------------------------------------------------------------------


        //删除
        function deleteWay(sale_opportunityId,customerId,linkmanId) {
            $.get('<c:url value="/deleteopp.do"/>',
                {"sale_opportunityId": sale_opportunityId,"customerId":customerId,"linkmanId":linkmanId},
                function (data) {
                    alert("刪除成功");
                })
        }

        //------------------------------------------------------------------------------------------------------------

        //新建销售机会
        $('#add').on('click', function () {
            layer.open({
                type: 2,
                offset: 't',
                title: '新建销售机会',
                area: ['1718px', '882px'],
                // area: ['1921.78px', '994.7px'],
                shadeClose: false, //点击遮罩关闭
                content: 'add.jsp',
            });
        });

        //------------------------------------------------------------------------------------------------------------

        //按钮操作
        //监听工具条
        table.on('tool(test)', function(obj){

            <%--if (${sessionScope.user.roleId!=1} && ${sessionScope.user.roleId!=2}){--%>
            <%--    layer.alert("对不起，您没有操作权限 ！");--%>
            <%--    return;--%>
            <%--}--%>
            var data = JSON.stringify(obj.data);
            $.ajax({
                url: '<c:url value="/getSj.do"/>',
                type:'post',
                dataType:'text',
                data:{
                    jsonString : data
                }
            })
            if (obj.event === 'sc') {
                layer.confirm('真的删除行么', {icon: 1, title:'提示'}, function (index) {
                    obj.del();
                    deleteWay(obj.data.sale_opportunityId,obj.data.customerId,obj.data.linkmanId);
                    layer.close(index);
                });
            }
            else if(obj.event === 'bj'){
                layer.open({
                    type: 2,
                    offset: 't',
                    title: '编辑销售机会',
                    area: ['1718px', '882px'],
                    // area: ['1921.78px', '994.7px'],
                    shadeClose: false, //点击遮罩关闭
                    content: 'edit.jsp',
                    // cancel: function(index, layero){
                    //     if(confirm('确定要关闭么')){ //只有当点击confirm框的确定时，该层才会关闭
                    //         layer.close(index);
                    //         bjsx;
                    //     }
                    //     return false;
                    // }
                });
            }
            else if(obj.event === 'zp'){
                layer.open({
                    type: 2,
                    offset: 't',
                    title: '指派销售机会',
                    area: ['1718px', '882px'],
                    // area: ['1921.78px', '994.7px'],
                    shadeClose: false, //点击遮罩关闭
                    content: 'dispatch.jsp',
                });
            }
        });




    });


</script>

</body>
</html>
